home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Peter Lewis / PNL Libraries / MyScan.p < prev    next >
Encoding:
Text File  |  1994-08-04  |  1.7 KB  |  74 lines  |  [TEXT/PJMM]

  1. unit MyScan;
  2.  
  3. interface
  4.  
  5.     function ScanDirectory (fs: FSSpec; doit: procPtr): OSErr;
  6. { function Doit(var fs:FSSpec; folder:boolean; path:str255; var pb:CInfoPBRec):boolean }
  7. { for folders, return true to scan contents }
  8. { for files return true if you delete the file - other changes to the file system would be bad... }
  9.  
  10. implementation
  11.  
  12.     uses
  13.         MyFileSystemUtils;
  14.  
  15.     function CallProc (var fs: FSSpec; folder: boolean; path: str255; var pb: CInfoPBRec; p: ptr): boolean;
  16.     inline
  17.         $205F, $4E90;
  18.  
  19.     function ScanDirectory (fs: FSSpec; doit: procPtr): OSErr;
  20.         var
  21.             pb: CInfoPBRec;
  22.             ret, folder: boolean;
  23.             path: str255;
  24.         procedure Scan (dirID: longInt);
  25.             var
  26.                 index, len: integer;
  27.                 oe: OSErr;
  28.         begin
  29.             index := 1;
  30.             repeat
  31.                 with pb do begin
  32.                     oe := MyGetCatInfo(fs.vRefNum, dirID, fs.name, index, pb);
  33.                     index := index + 1;
  34.                     if oe = noErr then begin
  35.                         fs.parID := dirID;
  36.                         folder := BAND(pb.ioFlAttrib, $10) <> 0;
  37.                         ret := CallProc(fs, folder, path, pb, doit);
  38.                         if folder and ret then begin
  39.                             len := length(path);
  40.                             path := concat(path, fs.name, ':');
  41.                             Scan(pb.ioDirID);
  42.                             path[0] := chr(len);
  43.                         end
  44.                         else if not folder and ret then begin
  45.                             index := index - 1;
  46.                         end;
  47.                     end;
  48.                 end;
  49.             until oe <> noErr;
  50.         end;
  51.         var
  52.             err: OSErr;
  53.             dummy: boolean;
  54.     begin
  55.         path := ':';
  56.         if fs.name <> '' then begin
  57.             err := MyGetCatInfo(fs.vRefNum, fs.parID, fs.name, 0, pb);
  58.             if err = noErr then begin
  59.                 if BAND(pb.ioFlAttrib, $10) <> 0 then begin
  60.                     Scan(pb.ioDirID);
  61.                 end
  62.                 else begin
  63.                     dummy := CallProc(fs, false, path, pb, doit);
  64.                 end;
  65.             end;
  66.         end
  67.         else begin
  68.             Scan(fs.parID);
  69.             err := noErr;
  70.         end;
  71.         ScanDirectory := err;
  72.     end;
  73.  
  74. end.